Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dyn-template

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dyn-template

Dynamic Template string

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

dyn-template

Dynamic Template string. It is all the same with Template Literal String in Javascript besides instead of returning a string, it returns a function whose return value is a string.

Installation

npm i dyn-template

Usage

import { dyn } from 'dyn-template'

let n = 0
const random = dyn`${() => ++n}. ${Math.random}`

while (n < 5) console.log(random())

// Maybe
// 
// 1. 0.7632479109972825
// 2. 0.31000327931995975
// 3. 0.014416508824629193
// 4. 0.7325147663760406
// 5. 0.8938454844327381

If the expression in template is a function, the function will be executed every time when the dynamic template is executed. On the other hand, if the expression is not a function, it will be calculated only once when the dynamic template is created.

import { dyn } from 'dyn-template'

const template = dyn`Compiled at ${Date.now()}, Running at ${Date.now}`

for (let n = 0; n < 1000; ++n) console.log(template()) 

// Maybe
// 
// Compiled at 1729781340083, Running at 1729781340083
// ...
// Compiled at 1729781340083, Running at 1729781340084
// ...
// Compiled at 1729781340083, Running at 1729781340085
// ...

Keywords

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc